﻿@namespace Microsoft.FluentUI.AspNetCore.Components
@inherits FluentComponentBase
<fluent-tree-item @ref=Element
                  class="@Class"
                  aria-label="@Text"
                  aria-expanded="@Expanded.ToAttributeValue()"
                  style="@Style"
                  id="@Id"
                  expanded="@Expanded"
                  selected="@Selected"
                  disabled="@Disabled"
                  @onselectedchange="@HandleSelectedChangeAsync"
                  @onexpandedchange="@HandleExpandedChangeAsync"
                  @attributes="AdditionalAttributes">

    @if (Owner?.ItemTemplate == null && !string.IsNullOrWhiteSpace(Text))
    {
        <span class="treeitem-text">@Text</span>
    }

    @if (IconExpanded != null || IconCollapsed != null)
    {
        <FluentIcon Value="@(Expanded ? (IconExpanded ?? IconCollapsed) : (IconCollapsed ?? IconExpanded))" Slot="start" />
    }

    @ChildContent

    @if (Owner != null && Items != null)
    {
        @if (Owner.LazyLoadItems && Items.Any() && !Expanded)
        {
            @* Lazy loading required a "fake" sub-item to simulate the [+] *@
            <fluent-tree-item>@FluentTreeView.LoadingMessage</fluent-tree-item>
        }
        else
        {
            foreach (var item in Items)
            {
                @FluentTreeItem.GetFluentTreeItem(Owner, item)
            }
        }
    }

</fluent-tree-item>
